/*
XBaseTools
Copyright (C) 2008 Matthew Perry

This library/program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This libary/program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

using System;

namespace BaseTools.Strings
{
	/// <summary>
	/// Parse information for StringParser
	/// </summary>
	public struct ParseInfo : IEquatable<ParseInfo>
	{
		/// <summary>
		/// The string literal character
		/// </summary>
		public char LiteralChar;
		
		/// <summary>
		/// The escape sequence character
		/// </summary>
		public char EscapeChar;
		
		/// <summary>
		/// The stop characters
		/// </summary>
		public char[] SpecialChars;
		
		/// <summary>
		/// The escape sequences
		/// </summary>
		public EscapeSequence[] Escapes;
		
		/// <summary>
		/// Whitespace characters
		/// </summary>
		public char[] Whitespace;
		
		/// <summary>
		/// Line characters
		/// </summary>
		public char[] Lines;
		
		/// <summary>
		/// Creates a ParseInfo
		/// </summary>
		/// <param name="LiteralChar">The string literal char</param>
		/// <param name="EscapeChar">The escape sequence char</param>
		/// <param name="SpecialChars">The stop chars</param>
		/// <param name="Escapes">The escape sequences</param>
		/// <param name="Whitespace">Whitespace chars</param>
		/// <param name="Lines">Line chars</param>
		public ParseInfo(char LiteralChar, char EscapeChar, char[] SpecialChars, EscapeSequence[] Escapes, char[] Whitespace, char[] Lines)
		{
			this.LiteralChar = LiteralChar;
			this.EscapeChar = EscapeChar;
			this.Escapes = Escapes;
			this.Whitespace = Whitespace;
			this.SpecialChars = SpecialChars;
			this.Lines = Lines;
		}
		
		#region Equals and GetHashCode implementation
		// The code in this region is useful if you want to use this structure in collections.
		// If you don't need it, you can just remove the region and the ": IEquatable<ParseInfo>" declaration.
		
		/// <summary>
		/// Equals
		/// </summary>
		/// <param name="obj"></param>
		/// <returns></returns>
		public override bool Equals(object obj)
		{
			if (obj is ParseInfo)
				return Equals((ParseInfo)obj); // use Equals method below
			else
				return false;
		}
		
		/// <summary>
		/// Equals
		/// </summary>
		/// <param name="other"></param>
		/// <returns></returns>
		public bool Equals(ParseInfo other)
		{
			// add comparisions for all members here
			return this.LiteralChar == other.LiteralChar && this.EscapeChar == other.EscapeChar &&
				this.Escapes.Equals(other.Escapes) && this.Whitespace.Equals(other.Whitespace) && this.SpecialChars.Equals(other.SpecialChars)
				&& this.Lines.Equals(other.Lines);
		}
		
		/// <summary>
		/// Xor'ed hash codes
		/// </summary>
		/// <returns></returns>
		public override int GetHashCode()
		{
			// combine the hash codes of all members here (e.g. with XOR operator ^)
			return LiteralChar.GetHashCode() ^ EscapeChar.GetHashCode() ^ SpecialChars.GetHashCode() ^ 
				Escapes.GetHashCode()
				^ Whitespace.GetHashCode() ^ Lines.GetHashCode();
		}
		
		/// <summary>
		/// Equals operator
		/// </summary>
		/// <param name="lhs"></param>
		/// <param name="rhs"></param>
		/// <returns></returns>
		public static bool operator ==(ParseInfo lhs, ParseInfo rhs)
		{
			return lhs.Equals(rhs);
		}
		
		/// <summary>
		/// Inequal operator
		/// </summary>
		/// <param name="lhs"></param>
		/// <param name="rhs"></param>
		/// <returns></returns>
		public static bool operator !=(ParseInfo lhs, ParseInfo rhs)
		{
			return !(lhs.Equals(rhs)); // use operator == and negate result
		}
		#endregion
	}
}
